//
//  YWViewController.m
//  网易新闻
//
//  Created by Yeewii@hotmail.com on 16/6/15.
//  Copyright © 2016年 Yeewii@hotmail.com. All rights reserved.
//

#import "YWTabBarController.h"
#import "ViewController.h"
#import "YWReadViewController.h"
#import "YWVideoViewController.h"
#import "YWTopicViewController.h"
#import "YWMeViewController.h"
#import "YWNavigationController.h"
@interface YWTabBarController ()

@end

@implementation YWTabBarController

+ (void)initialize
{
    UITabBarItem *appearance              = [UITabBarItem appearance];
    NSMutableDictionary *attrs            = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor redColor];
    [appearance setTitleTextAttributes:attrs forState:UIControlStateSelected];

    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 初始化所有的子控制器
    [self setupChildViewControllers];
}

/**
 * 初始化所有的子控制器
 */
- (void)setupChildViewControllers
{
    ViewController *newsVC         = [[ViewController alloc] init];
    [self setupOneChildViewController:newsVC title:@"新闻" image:@"night_tabbar_icon_news_normal" selectedImage:@"night_tabbar_icon_news_highlight"];

    YWReadViewController *readVC   = [[YWReadViewController alloc] init];
    [self setupOneChildViewController:readVC title:@"阅读" image:@"night_tabbar_icon_reader_normal" selectedImage:@"night_tabbar_icon_reader_highlight"];

    YWVideoViewController *videoVC = [[YWVideoViewController alloc] init];
    [self setupOneChildViewController:videoVC title:@"视频" image:@"night_tabbar_icon_media_normal" selectedImage:@"night_tabbar_icon_media_highlight"];

    YWTopicViewController *topicVC = [[YWTopicViewController alloc] init];
    [self setupOneChildViewController:topicVC title:@"话题" image:@"night_tabbar_icon_found_normal" selectedImage:@"night_tabbar_icon_found_highlight"];

    YWMeViewController *meVC       = [[YWMeViewController alloc] init];
    [self setupOneChildViewController:meVC title:@"我" image:@"night_tabbar_icon_me_normal" selectedImage:@"night_tabbar_icon_me_highlight"];
}

- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    vc.view.backgroundColor = [UIColor whiteColor];
    vc.title         = title;
    vc.tabBarItem.image         = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    [self addChildViewController:[[YWNavigationController alloc] initWithRootViewController:vc]];
}

@end
